<?php
// +----------------------------------------------------------------------
// | Crawler [ plugin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
// plugin command
namespace plugins\portal_promotion\command; 

use think\console\Command;

use think\console\input\Argument;
use think\console\input\Option;

use think\console\Input;
use think\console\Output;

use think\Db;

class Promotion extends Command
{
    protected function configure()
    {
        //argument
        //$this->addArgument('test', Argument::REQUIRED);
        //option
        //$this->addOption('site', 's', Option::VALUE_OPTIONAL, 'fenxiangdashi'); //选项值选填

        $this->setName('promotion')->setDescription('remark promotion end date');
    }
    /**
     * 定时执行命令 
     * @access public
     * @param  Input $input 
     * @param  Output $output 
     * @return void
     */
    protected function execute(Input $input, Output $output)
    {    
        
        $dates = [];
        $dates[] = date('Y-m-d');
        $dates[] = date("Y-m-d", strtotime("-1 day"));
        $dates[] = date("Y-m-d", strtotime("-2 days"));
       
        $postIds = Db::name('portal_promotion')
            ->where(['end_date' => ['in', $dates]])
            ->column('post_id');
        
    
        $savedIds = Db::name('portal_post')
            ->where(['id' => ['in', $postIds]])
            ->update(['recommended' => '0']);
        
        $output->writeln("portal promotion update end date success!");
    }

}
